package com.sisyphus.spinach.network.views;

import android.view.View;

import com.sisyphus.spinach.core.INetTask;

/**
 * 按键触发请求后，不可点击
 */
public class Debounce<T> implements INetTask.View<T> {

    private final View mView;

    private final INetTask.View<T> mTaskView;

    public Debounce(View view, INetTask.View<T> taskView) {
        mView = view;
        mTaskView = taskView;
    }

    @Override
    public void start() {
        mView.setEnabled(false);
        mTaskView.start();
    }

    @Override
    public void complete() {
        mView.setEnabled(true);
        mTaskView.complete();
    }

    @Override
    public void failure(Throwable throwable) {
        mTaskView.failure(throwable);
    }

    @Override
    public void success(T data) {
        mTaskView.success(data);
    }

}
